<?php

namespace app\api\module;

use app\common\model\Goods;
use app\common\model\Active as M;
use app\common\model\Server;
use app\common\model\Settings;
use think\facade\Db;
use function Symfony\Component\Translation\t;

class Active extends Common
{
    /**
     * 判断是否需要登录
     *
     * @param string $interface 待检测的接口
     * @return bool
     */
    protected function needLogin($interface)
    {
        //不需登录的接口
        $ignoreList = [
            ZFN_ACTIVE_INFO,
            ZFN_ACTIVE_SIGN,
        ];

        if (in_array($interface, $ignoreList)) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 执行接口操作
     *
     * @param $interface
     * @return array|string
     */
    public function exec($interface)
    {
        switch ($interface) {
            //【1001】活动详情
            case ZFN_ACTIVE_INFO:
                return $this->activeInfo();
            //【1002】活动报名
            case ZFN_ACTIVE_SIGN:
                return $this->activeSign();

            default:
                send_developer_error("模块【服务】中不存在接口【" . $interface . "】,核实文档后重试!");
        }
    }


    private function activeInfo()
    {
        $id=$this->essentialParam('id');
        $data = M::activeInfo($id);
        $this->insertResponse('',$data);
        return $this->response('活动详情');
    }

    private function activeSign()
    {
        $data = [
            'name' => $this->essentialParam('name'),
            'mobile' => $this->essentialParam('mobile'),
            'id' => $this->essentialParam('id')
        ];
        M::activeSign($data);
        return $this->response('已报名成功');
    }

}